const mongoose = require("mongoose");
mongoose.connect(
  "mongodb://testone:123456@101.200.161.230:27017/testone?authSource=testone"
);
let connect = mongoose.connection;
connect.on("open", () => {
  console.log("数据库连接成功");
});

connect.on("error", (err) => {
  console.log(err);
});

// 用户
const userSchema = new mongoose.Schema({
  username: String,
  telephone: String,
  password: String,
  imgPath: String,
});

const userModel = mongoose.model("user", userSchema, "user");

//Home轮播图
const imgsSchema = new mongoose.Schema({
  imgUrl: String,
});
const imgsModel = mongoose.model("imgs", imgsSchema, "imgs");
//Home Pet
const petSchema = new mongoose.Schema({
  imgUrl: String,
  petName: String,
  petAge: String,
  petSex: String,
  petType: String,
});
const petModel = mongoose.model("pet", petSchema, "pet");
//Home dictor
const dictorSchema = new mongoose.Schema({
  imgUrl: String,
  dictorName: String,
  dictorAge: String,
  dictorSex: String,
  dictorType: String,
});


const dictorModel = mongoose.model("dictor", dictorSchema, "dictor");

// Home essay
const essaySchema = new mongoose.Schema({
  // 文章标题
  name: String,
  // 文章类别
  type: {
    type: mongoose.Types.ObjectId,
    ref: 'essayType'
  },
  // 文章内容
  content: String,
  // 文章图片
  imgUrl: String,
  // 文章浏览量
  views: Number,
  // 文章点赞量
  likes: Number
})

// 文章类型
const essayTypeSchema = new mongoose.Schema({
  name: String
})

const essayModel = mongoose.model("essay", essaySchema, "essay");
const essayTypeModel = mongoose.model("essayType", essayTypeSchema, "essayType");





// 领养中心
const collarSchema = new mongoose.Schema({
  name: String,
  path: String,
  text: String,
  author: String,
  pl: {
    type: mongoose.Types.ObjectId,
    ref: 'pl'
  }
})

const collarModel = mongoose.model("collar", collarSchema, "collar");


//评论功能


const plschema = new mongoose.Schema({

  name: String,
  text: String,
  type: String,
  pid: {
    type: mongoose.Types.ObjectId,
    ref: 'pl'
  }

})

const plModel = mongoose.model("pl", plschema, "pl");


// 文章内容
const essayContentSchema = new mongoose.Schema({
  title: String,
  text: String,
  img: String,
})

const essayContentModel = mongoose.model("essayContent", essayContentSchema, "essayContent");

// 我的萌宠
const myPetSchema = new mongoose.Schema({
  name: String,
  img: String,
  eid: {
    type: mongoose.Types.ObjectId,
    ref: 'essayType'
  },
  vid: {
    type: mongoose.Types.ObjectId,
    ref: 'varietyType'
  },
  startTime: Date,
  endTime: Date,
  sex: {
    type: Number,
    default: 0
  },
  isJy: Number,
  uid: {
    type: mongoose.Types.ObjectId,
    ref: 'user'
  }
})
let myPetModel = mongoose.model("myPet", myPetSchema, "myPet")

//病例
let caseSchema = new mongoose.Schema({
  time: Date,
  hospital: {
    type: mongoose.Types.ObjectId,
    ref: 'pets'
  },
  //症状
  symptom: String,
  // 检测结果
  checkResult: String,
  //治疗建议
  suggest: String,
  imgs: Array,
  mid: {
    type: mongoose.Types.ObjectId,
    ref: 'myPet'
  }
})
let caseModel = mongoose.model("case", caseSchema, "case")
// 领养中心
const adoptSchema = new mongoose.Schema({
  // 姓名
  name: String,
  // 图片
  imgUrl: String,
  // 年龄
  age: String,
  // 性别
  sex: String,
  // 品种
  variety: {
    type: mongoose.Types.ObjectId,
    ref: 'varietyType'
  },
  // 发布时间
  date: {
    type: Date,
    default: Date.now
  },
  // 地区
  area: String
})

const adoptModel = mongoose.model("adopt", adoptSchema, "adopt");

// 品种类型
const varietyTypeSchema = new mongoose.Schema({
  name: String
})

const varietyTypeModel = mongoose.model("varietyType", varietyTypeSchema, "varietyType");


//talk
const addressBookSchema = new mongoose.Schema({
  uid: mongoose.Types.ObjectId,
  booksData: Array,
})
const addressBookModel = mongoose.model("addressBook", addressBookSchema, "addressBook")

//康佳奇
// 用户
var user_kjq = new mongoose.Schema({
  name: String, //用户名
  img: String,  //用户头像
})
var userkjq_model = mongoose.model("user_kjq", user_kjq, "user_kjq")

//医院
const Pets_hosp = new mongoose.Schema({
  name:String, //医院名称
  img:String,  //医院头像
  business:Number, //营业时间
  address:String, //医院地址
  long:Number, //医院距离
  score:Number, //医院评分
  host:{type:[]}
})
const pets_hosp = mongoose.model("pets", Pets_hosp, "pets")


// 医院项目
const hosp_project = new mongoose.Schema({
  name:String, //项目名称,
  price:Number, //项目价格
})
const project = mongoose.model("project", hosp_project, "project")

// 兼职类型
const part_type = new mongoose.Schema({
  name:String, //兼职名称,
})
const part_type_model = mongoose.model("part_type", part_type, "part_type")

//兼职
const part_jobb = new mongoose.Schema({
  name:String, //兼职名称,
  price:Number, //兼职价格
  address:String, //兼职地址
  userid:{type:mongoose.Types.ObjectId,ref:'user_kjq'}, //发布人id
  setid:{type:Array,default:[]}, //应聘人id,
  type:{type:mongoose.Types.ObjectId,ref:'part_type'}, //兼职类型
})
const part = mongoose.model("part", part_jobb, "part")

const help = new mongoose.Schema({
  userid:{type:mongoose.Types.ObjectId,ref:'user_kjq'}, //发布人id
  name:String, //求助信息,
  time:String, //求助时间
  price:Number, //求助价格
  img:Array, //求助图片
})
const help_model = mongoose.model("help", help, "help")


module.exports = {
  plModel,
  userModel,
  imgsModel,
  petModel,
  dictorModel,
  essayModel,
  essayTypeModel,
  collarModel,
  essayContentModel,
  myPetModel,
  adoptModel,
  varietyTypeModel,
  addressBookModel,
  caseModel,
  pets_hosp,
  project,
  part,
  userkjq_model,
  part_type_model,
  help_model
};
